<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html 
    xmlns = "http://www.w3.org/1999/xhtml"
    xmlns:h = "http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://xmlns.jcp.org/jsf/core"
    xmlns:p = "http://primefaces.org/ui"
    xmlns:ezcomp="http://xmlns.jcp.org/jsf/composite/ezcomp">
    <h:head>
        <f:event 
            listener="#{dashboardBean.enterDashboard ()}"
            type = "preRenderView" />
        <h:outputStylesheet library = "css" name = "basicViewStructure.css" />
        <h:outputStylesheet library = "css" name = "dashboardViewStructure.css" />
        <h:outputStylesheet library = "css" name = "calendarViewStructure.css" />
        <h:outputStylesheet library = "css" name = "eventViewStructure.css" />
        <title>Facelet Title</title>
    </h:head>
    <h:body id = "body">
        <div id = "mainBox" >
            <p:panel id = "dashboardHeaderBox">
                <h:graphicImage id="dashboardAppLogoImage" ismap="false" />
                    <h:form id = "headerModifyProfileForm" >
                        <h:outputText value="#{dashboardBean.managedUser.mail}"/>                             
                    </h:form>
                    <h:form id = "headerLogoutForm">
                        <p:commandLink 
                            action = "#{dashboardBean.exitDashboard ()}"
                            id = "logoutCommandLink"
                            value = "Logout" />
                    </h:form>
            </p:panel>
            <div id = "content">
                <p:panel id = "dashboardLeftBox" >
                    <p:panel 
                        id = "calendarsBox">
                        <p:dataScroller  
                            id = "calendarsList" 
                            value = "#{dashboardBean.calendars}" 
                            var = "calendar"
                            widgetVar="calendarsList">
                            <f:facet 
                                name="header" 
                                id = "calendarsDataScrollerHeader"
                                rendered="true" >
                                    Your Calendars
                            </f:facet>
                            <h:form 
                                id = "dashboardCalendarsListForm"
                                prependId = "false" >
                                <p:commandButton 
                                    style="background: ##{calendar.color}"
                                    rendered="true"
                                    value = "#{calendar.name}" >
                                    <p:ajax 
                                        async="true" 
                                        disabled = "false" 
                                        event="click" 
                                        immediate="true" 
                                        listener="#{editCalendarControllerBean.setManagedCalendar (calendar)}"  
                                        oncomplete="PF('editCalendarDialog').show()" 
                                        update = ":editCalendarDialog" /> 
                                </p:commandButton>
                                <p:growl 
                                    autoUpdate = "true"
                                    id = "dashboardCalendarListGrowl"
                                    showDetail = "true" 
                                    showSummary = "true" 
                                    sticky = "false"                                 
                                    widgetVar = "dashboardCalendarListGrowl" />
                            </h:form>
                        </p:dataScroller>
                        <p:panel id = "newCalendarBox">
                            <h:form id="newCalendarViewForm" >
                                <p:commandButton 
                                    id = "newCalendarButton" rendered = "true" value ="New Calendar !">
                                    <p:ajax 
                                        async="true" 
                                        disabled="false"
                                        event="click" 
                                        listener="#{newCalendarControllerBean.setNewManagedCalendar ()}"
                                        oncomplete="PF('newCalendarDialog').show()"
                                        partialSubmit="true" 
                                        update = ":newCalendarDialog" /> 
                                </p:commandButton>
                                <p:growl 
                                    sticky="false" 
                                    showDetail="true" 
                                    showSummary="true" id ="growl" 
                                    autoUpdate="true" 
                                    widgetVar="growl" />       
                            </h:form>
                        </p:panel>
                        <p:dialog 
                                closable = "true"
                                draggable = "true"
                                header = "Edit Calendar :"
                                id = "editCalendarDialog"
                                maximizable="false"
                                minimizable="false"
                                modal="true"
                                resizable="false"
                                widgetVar="editCalendarDialog"  >
                                <ezcomp:CalendarView 
                                    calendarViewControllerBean="#{editCalendarControllerBean}" 
                                    componentToUpdateAfterOk=":calendarsList"
                                    endorsedParentComponent = "editCalendarDialog"
                                    renderDeleteButton="true" 
                                    renderSharingForm = "true" />  
                            </p:dialog> 
                            <p:dialog 
                                closable = "true"
                                draggable = "true"
                                header = "New Calendar :" 
                                id = "newCalendarDialog" 
                                maximizable = "false" 
                                minimizable="false"
                                modal = "true"
                                resizable="false"
                                widgetVar="newCalendarDialog" >
                                <ezcomp:CalendarView  
                                    calendarViewControllerBean="#{newCalendarControllerBean}"
                                    componentToUpdateAfterOk = ":calendarsList"
                                    endorsedParentComponent="newCalendarDialog"
                                    renderDeleteButton="false"
                                    renderSharingForm = "false" />
                            </p:dialog>
                    </p:panel>
                </p:panel>
                <p:panel
                        id = "dashboardScheduleBox"
                        widgetVar = "dashboardScheduleBox" >
                        <h:form 
                            id = "dashboardScheduleForm" 
                            prependId = "false"
                            rendered = "true" >
                            <p:schedule 
                                centerHeaderTemplate = "month, agendaWeek, agendaDay"
                                draggable="false"
                                id="dashboardSchedule" 
                                leftHeaderTemplate="today" 
                                rendered = "true"
                                resizable = "false" 
                                rightHeaderTemplate="prev,next" 
                                showHeader = "true" 
                                value = "#{dashboardBean.scheduleModel}" 
                                widgetVar = "dashboardSchedule" >
                                <p:ajax 
                                    async = "true" 
                                    event = "dateSelect"
                                    ignoreAutoUpdate = "true"
                                    immediate = "true" 
                                    listener = "#{newEventControllerBean.setNewManagedEvent }" 
                                    oncomplete = "PF('dashboardNewEventDialog').show()" 
                                    update = ":dashboardNewEventDialog" />
                                <p:ajax 
                                    async = "true" 
                                    event = "eventSelect" 
                                    ignoreAutoUpdate = "true"
                                    immediate = "true" 
                                    listener = "#{editEventControllerBean.onEventSelect }" 
                                    update = ":dashboardEditEventDialog" />
                            </p:schedule>
                        </h:form>
                        <p:dialog 
                            closable = "true" 
                            draggable = "true" 
                            header = "New Event :" 
                            id = "dashboardNewEventDialog"
                            maximizable = "false" 
                            minimizable = "false"
                            modal = "true" 
                            resizable = "false" 
                            widgetVar = "dashboardNewEventDialog" >
                            <ezcomp:EventView
                                componentToUpdate = "dashboardSchedule"
                                deleteButtonRendered = "false"
                                eventController = "#{newEventControllerBean}"
                                sharingFunctionalitiesEnabled = "true"
                                widgetName = "dashboardNewEventDialog" />
                        </p:dialog>
                        <p:dialog 
                            closable = "true"
                            draggable = "true"
                            header = "Edit Event :"
                            id = "dashboardEditEventDialog" 
                            maximizable = "false"
                            minimizable = "false" 
                            modal="true"
                            resizable = "false"
                            widgetVar = "dashboardEditEventDialog" >
                            <ezcomp:EventView 
                                componentToUpdate = "dashboardSchedule"
                                deleteButtonRendered = "true"
                                eventController = "#{editEventControllerBean}"
                                sharingFunctionalitiesEnabled = "true"
                                widgetName = "dashboardEditEventDialog" />
                        </p:dialog>
                    </p:panel>
                <p:panel id = "dashboardRightBox"
                         widgetVar="dashboardRightBox">
                    <p:dataScroller 
                        id = "notificationsDataScroller" 
                        value="#{dashboardBean.notifications}" 
                        var = "notification" >
                        <f:facet 
                            name = "header" 
                            rendered="true" >
                            Notifications
                        </f:facet>
                        <p:panel>
                            <h:form
                                prependId = "false" >
                                <div class = "genericTableRow">
                                    <h:outputText 
                                        id = "notificationTitleLabel" 
                                        value = "#{notificationSectionBean.generateNotificationTitle ( notification )}"/>
                                </div>
                                <div class = "genericTableRow">
                                    <h:outputText 
                                        id = "notificationContentLabel" 
                                        value = "#{notificationSectionBean.generateNotificationContent ( notification )}"/>  
                                </div>
                                <div class = "genericTableRow">
                                    <p:commandButton 
                                        type="submit"
                                        value = "#{notificationSectionBean.getLeftButtonText ( notification )}" >
                                        <p:ajax 
                                            async = "true"
                                            disabled = "false"
                                            event = "click"
                                            listener = "#{notificationSectionBean.executeLeftAction ( notification )}" 
                                            update=":dashboardRightBox"
                                            partialSubmit="true"
                                            process="@form"/>
                                    </p:commandButton>
                                    <p:commandButton 
                                        type="submit"
                                        value = "#{notificationSectionBean.getRightButtonText ( notification )}" >
                                        <p:ajax 
                                            async = "true"
                                            disabled = "false"
                                            event = "click" 
                                            listener = "#{notificationSectionBean.executeRightAction ( notification )}" 
                                            update = ":dashboardRightBox"
                                            partialSubmit="true"
                                            process="@form"/>
                                    </p:commandButton>
                                </div>
                            </h:form>
                        </p:panel>
                    </p:dataScroller>
                </p:panel>
            </div>
        </div>
    </h:body>
</html>
